﻿<%@ Page Title="" Language="C#" MasterPageFile="~/pages/master/WebForm.Master" AutoEventWireup="true"
    CodeBehind="UserEdit.aspx.cs" Inherits="BF.Web.pages.BaseSystem.UserManagement.UserEdit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" language="javascript">
        //显示CheckBox的Tip
        function ShowToolTip(e, tex) {
            var obj = (e.srcElement) ? e.srcElement : (e.target) ? e.target : null;
            obj.title = tex.toString();
            //                debugger;
        }

        //重置
        function Doclear() {
            var gTreeHosKey = '<%=GetTreeHosKey() %>';
            window.location.href = "UserEdit.aspx?gTreeHospitalKey=" + gTreeHosKey;
            return false;
        }

        //保存页面
        function Save() {
            if (CheckInput()) {
                ChangeDiv();
            }
            return CheckInput();
        }

        //关闭窗口
        function DoClose() {
            winer.close();
            return false;
        }

        function SetValue(obj) {
            $("#ctl00_ContentPlaceHolder1_txtHosName").val(obj.sOrganizationName)
            $("#ctl00_ContentPlaceHolder1_hidNewHospitalName").val(obj.sOrganizationName)
            $("#ctl00_ContentPlaceHolder1_hidHosCode").val(obj.gkey)
        }

        //选择机构
        function Choose() {
            winer.OpenWin('请选择机构', '../pages/BaseSystem/UserManagement/ChooseLowerOrganization.aspx', 900, 500, false, this);
            return false;
        }

        function Update(values, gTreeHosKey) {
            $(parent.document).find(".x-window-header-text").html("用户信息修改");
            window.location.href = 'userEdit.aspx?sKey=' + values + '&gTreeHospitalKey=' + gTreeHosKey;
        }

        $(function () {
            if (GetUrlParam("sKey") == null || GetUrlParam("sKey") == "") {
                $("#ctl00_ContentPlaceHolder1_btnSeach").hide();
            }
            else {
                $("#ctl00_ContentPlaceHolder1_btnSeach").show();
            }
        });


        //URL参数获取
        function GetUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }

    </script>
    <%--页面验证--%>
    <script type="text/javascript" language="javascript">
        function CheckInput() {
            var result = $("#aspnetForm").validate({
                rules: {
                    ctl00$ContentPlaceHolder1$sLoginName: {//用户名
                        required: true,
                        maxlength: 20,
                        LoginName: true
                    },
                    ctl00$ContentPlaceHolder1$sPassword: {//密码
                        required: true,
                        maxlength: 20,
                        minlength: 3
                    },
                    ctl00$ContentPlaceHolder1$hidHosCode: {//机构选择
                        required: true
                    }
                },
                messages: {
                    ctl00$ContentPlaceHolder1$hidHosCode: { required: "*必填" }
                },
                errorClass: "errorClass"
            });
            return result.form();
        }

        //角色选择
        jQuery.validator.addMethod("UserRoles", function () {
            var result = false;

            $("input[name*='ctl00$ContentPlaceHtml$UserRoles']").each(function () {
                if (this.checked) {
                    result = true;
                }
            });
            return result;
        }, "*必须选择一个角色。");

        //用户名验证
        jQuery.validator.addMethod("LoginName", function () {
            var result = false;

            var str = document.getElementById("ctl00_ContentPlaceHolder1_sLoginName").value;
            var reg = /[^A-Za-z0-9_]/g
            if (reg.test(str)) {
                result = false;
            } else {
                result = true;
            }
            return result;
        }, "*用户名必须为数字字母下滑线。");
    </script>
    <script type="text/javascript">
        function OpenImportHumanList() {
            $("#ctl00_ContentPlaceHolder1_hidType").val("1");
            winer.OpenWin('选择人力资源信息', '/pages/BaseSystem/UserManagement/ChooseLowerHumanList.aspx', 900, 525, false, this);
            return false;
        }

        //获取人员
        function SetHumanValue(obj) {
            $("#ctl00_ContentPlaceHolder1_sUserName").val(obj.sName);
            $("#ctl00_ContentPlaceHolder1_txtHosName").val(obj.sOrganizationName);
            $("#ctl00_ContentPlaceHolder1_hidHosCode").val(obj.sOrganizationKey);
            $("#ctl00_ContentPlaceHolder1_sEmail").val(obj.sEmail);
            $("#ctl00_ContentPlaceHolder1_iSex").val(obj.sSexCode);
            $("#ctl00_ContentPlaceHolder1_hidgHumanKey").val(obj.sHumanKey);
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <!--保存传递过来的人力资源Key-->
    <asp:HiddenField ID="hidType" Value="0" runat="server" />
    <!--当前人员的Key-->
    <asp:HiddenField ID="hid" Value="0" runat="server" />
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="content01">
        <thead>
            <tr>
                <td style="width: 70px">
                </td>
                <td>
                </td>
                <td style="width: 50px">
                </td>
                <td>
                </td>
            </tr>
        </thead>
        <tbody>
            <tr style="height: 18px;">
                <td colspan="4">
                </td>
            </tr>
            <tr>
                <td align="right">
                    <span style="color: Red">*</span>用户编号：
                </td>
                <td align="left">
                    <tll:DataTextBox ID="sLoginName" runat="server" FeildName="sLoginName" TableName="sys_UserInfo"></tll:DataTextBox>
                    <%--用户ID--%>
                    <tll:DataHiddenField ID="UserID" runat="server" />
                </td>
                <td align="right">
                    性别：
                </td>
                <td align="left">
                    <tll:DataDropDownList ID="iSex" runat="server" FeildName="iSex" TableName="sys_UserInfo">
                    </tll:DataDropDownList>
                </td>
            </tr>
            <tr>
                <td align="right">
                    用户名：
                </td>
                <td align="left">
                    <tll:DataTextBox ID="sUserName" runat="server" FeildName="sUserName" TableName="sys_UserInfo"></tll:DataTextBox>
                </td>
                <td align="right">
                    <span style="color: Red">*</span>密码：
                </td>
                <td align="left">
                    <tll:DataTextBox ID="sPassword" TextMode="Password" Width="170px" runat="server"
                        FeildName="sPassword" TableName="sys_UserInfo"></tll:DataTextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                    <span style="color: Red">*</span>所属机构：
                </td>
                <td align="left">
                    <tll:DataTextBox ID="txtHosName" Text="" ReadOnly="true" runat="server"></tll:DataTextBox>
                    <asp:HiddenField ID="hidHosCode" runat="server" />
                    <asp:Button ID="btnSeach" runat="server" TabIndex="0" Text="..." OnClientClick="return Choose();">
                    </asp:Button>
                    <asp:HiddenField ID="hidSeach" runat="server" />
                </td>
                <td align="right">
                    邮箱：
                </td>
                <td>
                    <tll:DataTextBox ID="sEmail" runat="server" FeildName="sEmail" TableName="sys_UserInfo"></tll:DataTextBox>
                </td>
            </tr>
            <tr>
                <td align="right" style="vertical-align: top">
                    用户角色：
                </td>
                <td colspan="3" align="left">
                    <div style="margin-left: -8px;">
                        <asp:CheckBoxList ID="UserRoles" runat="server" RepeatColumns="4" RepeatDirection="Horizontal"
                            EnableTheming="False" />
                    </div>
                    <input id="hidName" type="hidden" name="hidName" />
                </td>
            </tr>
            <tr>
                <td align="right">
                    是否启用：
                </td>
                <td colspan="4">
                    <div style="margin-left: -6px;">
                        <asp:CheckBox ID="isapproved" runat="server" Checked="true" /></div>
                </td>
            </tr>
            <tr style="height: 18px;">
                <td colspan="4">
                </td>
            </tr>
        </tbody>
    </table>
    <table width="100%" height="36" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td align="center">
                <asp:Button ID="lbtnReSet" runat="server" TabIndex="0" Text="新增" class="btn04" OnClientClick="return Doclear();" />&nbsp;
                <asp:Button ID="lbtnSave" runat="server" TabIndex="0" Text="保存" class="btn04" OnClick="lbtnSave_Click"
                    OnClientClick="return Save();" />&nbsp;
                <asp:Button ID="lbtnClose" runat="server" OnClientClick="return DoClose() ;" TabIndex="0"
                    Text="关闭" class="btn04" />
            </td>
        </tr>
    </table>
    <asp:UpdatePanel ID="Updatepanel1" runat="server">
        <ContentTemplate>
            <asp:HiddenField ID="hidgHumanKey" runat="server" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="lbtnSave" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>
